import { FastifyReply, FastifyRequest } from 'fastify';
import { ComponentType } from 'react';

import { HtmlScriptProps, HtmlStyleProps, WindowScriptProps } from '../render/html-tags';

interface MetaOption {
    name: string;
    value: string;
}

interface RobotsOption {
    enable: boolean;
}

interface SEOOption {
    title?: string;
    keywords?: string;
    description?: string;

    robots?: RobotsOption;
}

interface HeaderOption {
    icon?: string;
    sloganLogo?: string;
    staticPath?: string;
}

interface RenderOption {
    rootElement: ComponentType;
    pageName: string;
    request: FastifyRequest<any>;
    reply: FastifyReply<any>;

    getConfig: <T = any>(name: string) => T;
}

interface PageInfo {
    seo?: SEOOption;
    viewport?: string;
    lang?: 'zh-CN';
    dir?: 'ltr' | 'rtr';
    charset?: 'utf-8';
}

interface ControllerReply<T = any> {
    initData: T;

    pageInfo?: PageInfo;
}

// use this when rendered
interface RenderModel<T = any> {
    controllerReply: ControllerReply<T>;

    renderOption: RenderOption;

    metas: Array<MetaOption>;

    windowScripts: Array<WindowScriptProps>;

    injectedScripts: Array<HtmlScriptProps>;
    injectedStyles: Array<HtmlStyleProps>;

    headerOption?: HeaderOption;
}

type ControllerMethod = Function & {
    reactRootElement: ComponentType;
};

export {
    ControllerMethod,
    HeaderOption,
    RenderOption,
    ControllerReply,
    PageInfo,
    RenderModel,
    MetaOption,
    RobotsOption,
    SEOOption,
};
